package mytrain.kirayous;

import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisException;

public class Service {

    private long id=Thread.currentThread().getId();


    @Test
    public void test(){

       Jedis jedis= JedisUtils.getJedisConnection();
       jedis.set("test","dasdadsa");
       jedis.close();

    }
    public void service()
    {

        Jedis jedis=JedisUtils.getJedisConnection();


        String value=jedis.get(String.valueOf(id));
        try {
            if (value==null|| value.equals(""))
            {
                jedis.setex(String.valueOf(id),20,(Long.MAX_VALUE-20)+"");
            }else
            {
                long temp=20-(Long.MAX_VALUE-jedis.incr(id+""));
                System.out.println("用户"+id+"使用了"+temp+"次");
            }
        }catch (JedisException e)
        {
            System.out.println("用户"+id+"已达到最大使用次数，请升级会员");
        } finally {
          jedis.close();
        }
    }
}
